package uk.co.q3c.deplan.client.util;

import org.testng.Assert;
import org.testng.annotations.Test;

import uk.co.q3c.deplan.client.domain.DomainKind;
import uk.co.q3c.deplan.client.domain.task.BaseTask;
import uk.co.q3c.deplan.client.ui.mock.view.ProjectTaskViewMock;
import uk.co.q3c.deplan.client.ui.view.Q3CoreView;
import uk.co.q3c.deplan.client.ui.view.Viewtags;
import uk.co.q3c.deplan.server.unit.dao.LocalDatastoreTestCase;

@Test
public class HistoryToken_UT extends LocalDatastoreTestCase {
	Q3CoreView tdv;
	BaseTask pt;

	@Override
	protected void beforeMethod() throws Exception {
		super.beforeMethod();
		pt = new BaseTask(connection);
		pt.save();
		tdv = new ProjectTaskViewMock();
	}

	public void constructToken() {
		String s = HistoryToken.constructHistoryToken("AbstractTaskView", pt);
		Assert.assertEquals(s, "AbstractTaskView:BaseTask:9");
	}

	public void parse() {
		HistoryTokenRecord htr = HistoryToken.parseToken("AbstractTaskView:BaseTask:9");
		Assert.assertEquals(htr.kind, DomainKind.AbstractTask);
		Assert.assertEquals(htr.id, 9);
		Assert.assertEquals(htr.viewName, Viewtags.AbstractTaskView);
	}

	public void constructrecord() {
		HistoryTokenRecord htr = HistoryToken.constructRecord(tdv, pt);
		Assert.assertEquals(htr.kind, DomainKind.AbstractTask);
		Assert.assertEquals(htr.id, 9);
		Assert.assertEquals(htr.viewName, Viewtags.AbstractTaskView);

	}

	public void constructTokenFromRecord() {
		HistoryTokenRecord htr = HistoryToken.constructRecord(tdv, pt);
		String s = HistoryToken.constructHistoryToken(htr);
		Assert.assertEquals(s, "AbstractTaskView:BaseTask:9");
	}
}
